package com.ty.common.converter;

import org.springframework.core.convert.converter.Converter;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author 天宇宇宇宇宇 @Data 2020/12/16 10:18
 *     <p>自定义类型转换器 String -> Date
 */
public class StringToDateConverter implements Converter<String, Date> {
  @Override
  public Date convert(String source) {
    System.out.println("转换类型");
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    Date date = null;
    try {
      date = dateFormat.parse(source);
    } catch (ParseException e) {
      e.printStackTrace();
    }
    return date;
  }
}
